
import { View, Image } from '@tarojs/components'
import { AtButton } from 'taro-ui'
import headerBg from "../../assets/images/headbg.jpg"
import GlobalFooter from '../../components/GlobalFooter'
import Taro from '@tarojs/taro'
import './index.scss'


import questionResults from '../../data/question_results.json'
import questions from '../../data/questions.json'
import { getBestQuestionResult } from '../../utils/bizUtils'


// 测试结果页
export default () => {

  // 获取做题页传递过来的答案列表
  const answerList = Taro.getStorageSync('answerList')
  if(!answerList || answerList.length < 1) {
    Taro.showToast({
      title: '答案为空',
      icon: 'error',
      duration: 3000
    })
  }

  // 获取测试结果
  const result = getBestQuestionResult(answerList,questions,questionResults)

  return (
    <View className='result-page'>
      <View className='title-box'>
        <View className='at-article__h1 title'>
          {result.resultName}
        </View>
        <View className='at-article__h2 subTitle'>{result.resultDesc}</View>
        <AtButton type='primary' circle className='enterBtn' onClick={() => {
          Taro.reLaunch({
            url: '/pages/index/index'
          })
        }}>返回主页</AtButton>
      </View>
      <View className="bg"></View>
      <Image src={headerBg} className='headerBg' mode='aspectFill'/>
      <GlobalFooter />
    </View>
  )
}
